package com.example.xinhuayipin.ui.activity;


import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Handler;
import android.os.Message;

import com.example.commons.BaseActivity;
import com.example.commons.annotations.ViewInject;
import com.example.commons.utils.FpUtil;
import com.example.commons.utils.RxTimerUtil;
import com.example.xinhuayipin.R;
import com.example.xinhuayipin.app.MyService;

import winuim.fingerprint.sdk.FpScanner;

@ViewInject(getLayoutId = R.layout.activity_splash)
public class SplashActivity extends BaseActivity {

    private FpScanner mScanner;
    private FpUtil mFpUtil;

    @Override
    protected void initialize() {
        super.initialize();
        setTheme(R.style.AppTheme);
    }

    @Override
    protected void initView() {
        super.initView();
        RxTimerUtil.timer(3000,()->{
            skipAnotherActivity(MainActivity.class);
            finish();
        });
    }

    @Override
    protected void initData() {
        super.initData();
        if (mFpUtil == null) mFpUtil = new FpUtil();
        try{
            mScanner = mFpUtil.startFP(mContext, mHandler);
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    @Override
    protected void startServices() {
        super.startServices();
        startService(new Intent(mContext, MyService.class));
    }

    @SuppressLint("HandlerLeak")
    Handler mHandler = new Handler(){
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
        }
    };

    @Override
    protected void onDestroy() {
        super.onDestroy();
        mScanner.Close();
        mFpUtil.stop();
        mFpUtil = null;
    }
}
